<?php
function edit_bckyayasan($config,$param){
	$desc = trim($param['descyaya']);
	if ($desc!=""){
		$db = new db($config);
		$que = "UPDATE `deskripsi` SET `deskripsi`='$desc' WHERE `page` = 'yayasan';";
		$db->exec($que);
		$_SESSION['editted'] = 'Sukses edit deskripsi Yayasan';
	}
	header('Location: '.$config['home_url']."backend/yayasan");
}

function add_bckyayasanfoto($config,$param){
	$uploaddir = $config['image_path'].'yayasan'.DIRECTORY_SEPARATOR.'slide'.DIRECTORY_SEPARATOR;
	$preddir = $config['image_path'].'yayasan'.DIRECTORY_SEPARATOR.'pre'.DIRECTORY_SEPARATOR;
	$limitedext = array("jpg","jpeg","png","bmp");
	$ext = strrchr($_FILES['gambar']['name'],'.');
	$ext = strtolower($ext);
	$getExt = explode('.',$ext);
	$getName = explode('.',$_FILES['gambar']['name']);
	$getName = helper::slugging($getName[0]);
	$file_ext = $getExt[count($getExt)-1];
	$file_name = $getName.".".$file_ext;
	$uploadfile = $uploaddir.$file_name;
	if (!in_array($file_ext,$limitedext)) {
		$_SESSION['editted'] = "Tipe file salah<br />Tipe file yang diperbolehkan adalah jpg, jpeg, bmp, png.";
	} else {
//		echo $_FILES['gambar']['tmp_name'];
		echo "\n".$uploadfile;
		if (move_uploaded_file($_FILES['gambar']['tmp_name'], $uploadfile)) {
			// process for thumbnail image
			//$file_name = $_FILES['gambar']['name'];
			echo "\n".$file_name;
			//die();
			WideImage::load($uploadfile)->resize(790,250,'fill')->saveToFile($uploadfile);	//slide
			WideImage::load($uploadfile)->resize(154,50,'fill')->saveToFile($preddir.$file_name);	//pre
			$_SESSION['editted'] = "Sukses upload gambar";
		} else {
			switch ($_FILES['gambar']['error']) {
				case 2:
					$_SESSION['editted'] = "Error: Ukuran gambar melebihi batas<br />Batas ukuran file adalah 1 MB";
					break;
				case 7:
					$_SESSION['editted'] = "Error: Tidak dapat disimpan dalam server";
					break;
				default:
					$_SESSION['editted'] = "Error: Unknown error ".$_FILES['gambar']['error'];
			}
		}
	}
	//die();
	header('Location: '.$config['home_url']."backend/yayasan");
}

function del_bckyayasanfoto($config,$param){
	$img=$param['img'];
	$uploaddir = $config['image_path'].'yayasan'.DIRECTORY_SEPARATOR.'slide'.DIRECTORY_SEPARATOR;
	$preddir = $config['image_path'].'yayasan'.DIRECTORY_SEPARATOR.'pre'.DIRECTORY_SEPARATOR;
	echo $uploaddir;
	echo $preddir;
//	die();
	unlink($uploaddir.$img);
	unlink($preddir.$img);
	$_SESSION['editted'] = 'Sukses hapus foto';
	header('Location: '.$config['home_url']."backend/yayasan");
}

function edit_bckyayasankontak($config,$param){
	$notelp = trim($param['notelp']);
	$email = trim($param['email']);
	$alamat = trim($param['alamat']);
	var_dump($param);
	$db = new db($config);
	$que = "UPDATE `kontak` SET `telp`=\"$notelp\", `email`=\"$email\", `alamat`=\"$alamat\" WHERE `page` = 'yayasan';";
	$db->exec($que);
	$_SESSION['editted'] = 'Sukses edit kontak';
	header('Location: '.$config['home_url']."backend/yayasan");
}
